package com.easyframe.system.module;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.struts2.ServletActionContext;

import com.easyframe.system.service.RoleService;

public class RoleAction extends BaseAction {
	private RoleService roleService;

	public RoleService getRoleService() {
		return roleService;
	}

	public void setRoleService(RoleService roleService) {
		this.roleService = roleService;
	}

	// getGridData
	public String getGridData() throws IOException {
/*		HttpServletResponse response = ServletActionContext.getResponse();
		 response.setContentType("text/json; charset=UTF-8");  //处理中文问题的必须的代码
		PrintWriter out = null;

		JqgridReqData jqReq = new JqgridReqData();
		boolean isOrgaRela = false;
		int organizationId = 0;
			out = response.getWriter();
		String jsonString = (roleService.getGridData(jqReq, isOrgaRela,
				organizationId)).toString();

		out.print(jsonString);
		out.flush();
		out.close();*/
	     //假设查询结果是一个封装了查询List的POJO对象，注意，调用方法的参数，具有分页功能，分页参数，可以通过Struts2的Action属性自动获取
	    // UserSearchTo to  = this.service.findTo( page, rows, sidx, sord);
	     
	     //封装成JSON对象返回,这里使用了json-lib包，要注意，这个包要用到几个其他的jar包，主要包括commons-lang 2.4、commons-beanutils 1.7.0、commons-collections 3.2、commons-logging 1.1.1以及ezmorph 1.0.6
		
		
	HttpServletResponse response = ServletActionContext.getResponse();
	     response.setContentType("text/json; charset=UTF-8");  //处理中文问题的必须的代码
	     PrintWriter out = response.getWriter();
	     
	     
	     JSONObject obj = new JSONObject();  
	   
	     obj.put("page", 1);    //当前页
	     obj.put("total",100);    //总页数
	     obj.put("records",10000);   //总记录数
	     
	     JSONArray lineitemArray = new JSONArray();
	  
	    for(int i=0;i<2;i++){
	      JSONObject o = new JSONObject();
	      o.put("code", 1);
	      o.put("name", "admin");
	      lineitemArray.add(o);
	     }
	     
	     obj.put("rows", lineitemArray);    //具体的Table显示内容
	    // System.out.println("test"+obj.toString());
	     out.print(obj.toString());
	 	out.flush();
		out.close();
		return null;
	}
}
